home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / AlexNeXTSTEPSource / Source / Chapter8_Prefs / Money / PrefsController.m < prev    next >
Text File  |  1995-06-12  |  2KB  |  125 lines

  1. #import <appkit/appkit.h>
  2. #import "PrefsController.h"
  3. #import "SwitchView.h"
  4.  
  5. @implementation PrefsController
  6.  
  7. #define TRUNCATE 0
  8. #define PROMPT 1
  9. #define OFF 0
  10. #define ON 1
  11.  
  12. + initialize
  13. {
  14.     // make sure that self is a PrefsController
  15.     // class before setting class initialization:
  16.     // this prevents subclasses from performing
  17.     // reinitialization
  18.     if (self == [PrefsController class])
  19.         {
  20.         const char *appName = [NXApp appName];
  21.  
  22.         static NXDefaultsVector theDefaults =
  23.             {
  24.                 {"Truncate", "NO"},
  25.                 {"Prompt", "NO"},
  26.                 {NULL, NULL}
  27.             };
  28.  
  29.         NXRegisterDefaults(appName, theDefaults);
  30.         }
  31.     return self;
  32. }
  33.  
  34. - awakeFromNib
  35. {
  36.     const char *appName = [NXApp appName];
  37.     const char *truncateFlag;
  38.  
  39.     truncateFlag =
  40.         NXGetDefaultValue(appName, "Truncate");
  41.     // make sure truncateFlag is not NULL before
  42.     // comparing it
  43.     if (truncateFlag)
  44.         {
  45.         if (strcasecmp(truncateFlag, "YES") == 0)
  46.             [truncateSwitch setState:ON];
  47.         else
  48.             [truncateSwitch setState:OFF];
  49.         }
  50.     return self;
  51. }
  52.  
  53. - setTruncate:sender
  54. {
  55.     const char *appName = [NXApp appName];
  56.     int state = [truncateSwitch state];
  57.     if (state == OFF)
  58.         NXWriteDefault(appName, "Truncate", "NO");
  59.     else
  60.         NXWriteDefault(appName, "Truncate", "YES");
  61.     return self;
  62. }
  63.  
  64. - (BOOL)shouldTruncate
  65. {
  66.     const char *truncateFlag;
  67.     const char *appName = [NXApp appName];
  68.  
  69.     // value in database may be newer than value
  70.     // in registration table because of Prefs
  71.     // panel; thus, update value in table to
  72.     // match value in database
  73.     NXUpdateDefault(appName, "Truncate");
  74.     // get value from registration table
  75.     // now that it's been updated
  76.     truncateFlag =
  77.         NXGetDefaultValue(appName, "Truncate");
  78.     // make sure truncateFlag is not NULL before
  79.     // comparing it
  80.     if (truncateFlag)
  81.         {
  82.         if (strcasecmp(truncateFlag, "YES") == 0)
  83.             return YES;
  84.         }
  85.     return NO;
  86. }
  87.  
  88. - displayPrefsPanel:sender
  89. {
  90.     if (!prefsPanel)
  91.         {
  92.         [NXApp loadNibSection:"Prefs.nib"
  93.             owner:self withNames:NO];
  94.         [switchView switchToView:truncateSwitch];
  95.         }
  96.     [prefsPanel makeKeyAndOrderFront:nil];
  97.     return self;
  98. }
  99.  
  100. - showAccessoryView:sender
  101. {
  102.     int index;
  103.     id popUpList;
  104.  
  105.     // the popuplist is the button's target
  106.     popUpList = [popUpButton target];
  107.     // get title of selected item and
  108.     // then get index of title in
  109.     // popuplist
  110.     index = [popUpList indexOfItem:
  111.             [popUpList selectedItem]];
  112.     switch(index)
  113.         {
  114.         case TRUNCATE:
  115.             [switchView switchToView:truncateSwitch];
  116.             break;
  117.         case PROMPT:
  118.             [switchView switchToView:promptSwitch];
  119.             break;
  120.         }
  121.     return self;
  122. }
  123.  
  124. @end;
  125.